require('../fonts/iconfont.css')
require('../less/register.less')

document.ready(function(){
    
    const account=document.querySelector("#account");
    const pawd=document.querySelector("#pawd")
    const confirm=document.querySelector("#confirm");
    const verification=document.querySelector("#verification");
    const mesage=document.querySelector("#mesage");
    const subm=document.querySelector("#subm");
    const mesageb=document.querySelector("#mesageb");
    const mesageee=document.querySelector("#mesageee");
    const btn10=document.querySelector("#btn10");
    const patl=document.querySelector("#Patl")

    let security=null;
    function secur(){
        let captcha1 = new CaptchaMini(
            {
                fontSize:60,
                lineNum: 6,
            }
        );
        captcha1.draw(document.querySelector('#captcha1'),function(r) {
            
            security=r;
        })
    }
    secur()
    subm.addEventListener("click",function(){
        if (until.isPhone(account.value)) {
            mesage.textContent='手机号不合法'
        }else if(verification.value.toLowerCase()!=security.toLowerCase()){
            mesage.textContent='您的验证码不正确'
        }else if(!pawd.value){
            mesage.textContent='您的密码格式错误'
        }else if(confirm.value!=pawd.value){
            mesage.textContent='两次的输入密码不一样'
        }else{
            mesage.textContent=''

            $http.post('/users/add',{account:account.value,password:pawd.value},function(res){
                if(res.status===0){
                    until.Registrat('success','注册成功')
                    // mesageee.style.display='block';
                    // mesageb.textContent='注册成功';
                    setTimeout(function(){
                        location.href='login.html';
                    },2000)
                }else{
                    until.Registrat('failed',res.msg)
                    
                }
            })
        }

        
    })
    
    patl.addEventListener('click',function(){
       location.href='./login.html'
    })
})